/***
 * Andmin - Joomla administrator access from Android phone
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
 * @author codegravity.com
 * @copyright (C) 2011 by Matej Koval - All rights reserved!
 * @website http://www.codegravity.com
 */

package com.codegravity.mobile.andmin;

import android.content.Context;
import android.content.SharedPreferences;

public class AndminSetting {
	// key name of Setting in system
	private static final String CONFIGURATION_NAME = "ServerConfiguration";
	private static String webUrl = "";
	private static String folderAdministrator = "";
	private static String username = "";
	private static String password = "";
	private static String httpAuthUsername = "";
	private static String httpAuthPassword = "";
	private static String joomplaComponent = "";
	private static boolean isFirstRun = true;
	
	/**
	 * @return the joomplaComponent
	 */
	public static String getJoomplaComponent() {
		return joomplaComponent;
	}
	/**
	 * @param joomplaComponent the joomplaComponent to set
	 */
	public static void setJoomplaComponent(String joomplaComponent) {
		AndminSetting.joomplaComponent = joomplaComponent;
	}
	/**
	 * @return the webUrl
	 */
	public static String getWebUrl() {
		return webUrl;
	}
	/**
	 * @param webUrl the webUrl to set
	 */
	public static void setWebUrl(String webUrl) {
		AndminSetting.webUrl = webUrl;
	}
	/**
	 * @return the folderAdministrator
	 */
	public static String getFolderAdministrator() {
		return folderAdministrator;
	}
	/**
	 * @param folderAdministrator the folderAdministrator to set
	 */
	public static void setFolderAdministrator(String folderAdministrator) {
		AndminSetting.folderAdministrator = folderAdministrator;
	}
	/**
	 * @return the username
	 */
	public static String getUsername() {
		return username;
	}
	/**
	 * @param username the username to set
	 */
	public static void setUsername(String username) {
		AndminSetting.username = username;
	}
	/**
	 * @return the password
	 */
	public static String getPassword() {
		return password;
	}
	/**
	 * @param password the password to set
	 */
	public static void setPassword(String password) {
		AndminSetting.password = password;
	}
	/**
	 * @return the httpAuthUsername
	 */
	public static String getHttpAuthUsername() {
		return httpAuthUsername;
	}
	/**
	 * @param httpAuthUsername the httpAuthUsername to set
	 */
	public static void setHttpAuthUsername(String httpAuthUsername) {
		AndminSetting.httpAuthUsername = httpAuthUsername;
	}
	/**
	 * @return the httpAuthPassword
	 */
	public static String getHttpAuthPassword() {
		return httpAuthPassword;
	}
	/**
	 * @param httpAuthPassword the httpAuthPassword to set
	 */
	public static void setHttpAuthPassword(String httpAuthPassword) {
		AndminSetting.httpAuthPassword = httpAuthPassword;
	}
	/**
	 * @return the isFirstRun
	 */
	public static boolean isFirstRun() {
		return isFirstRun;
	}
	/**
	 * @param isFirstRun the isFirstRun to set
	 */
	public static void setFirstRun(boolean isFirstRun) {
		AndminSetting.isFirstRun = isFirstRun;
	}
	/***
	 * 
	 * function is used to save setting in the system
	 */
	
	public static void Save(Context context) {
		SharedPreferences settings = context.getSharedPreferences(CONFIGURATION_NAME,Context.MODE_PRIVATE);
    	SharedPreferences.Editor editor = settings.edit();
    	editor.putString("webUrl", getWebUrl());
    	editor.putString("folderAdministrator", getFolderAdministrator());
    	editor.putString("joomplaComponent", joomplaComponent);
    	editor.putString("username", getUsername());
    	editor.putString("password", getPassword());
    	editor.putString("httpAuthUsername", getHttpAuthUsername());
    	editor.putString("httpAuthPassword", getHttpAuthPassword());
    	editor.putBoolean("isFirstRun", false);
    	editor.commit();
	}
	/***
	 * 
	 * function is used to load setting from system.
	 */
	public static void Load(Context context) {
		SharedPreferences settings = context.getSharedPreferences(CONFIGURATION_NAME, Context.MODE_PRIVATE);
		webUrl = settings.getString("webUrl", "");
		folderAdministrator = settings.getString("folderAdministrator", "");
		joomplaComponent = settings.getString("joomplaComponent", "");
		username = settings.getString("username", "");
		password = settings.getString("password", "");
		httpAuthUsername = settings.getString("httpAuthUsername", "");
		httpAuthPassword = settings.getString("httpAuthPassword", "");
		isFirstRun =  settings.getBoolean("isFirstRun", true);
	}	
	/***
	 * 
	 * get full url of website to connect.
	 */
	public static String getFullWebUrl() {
		return webUrl + "/" + folderAdministrator + "/index.php?option=" + getJoomplaComponent();
	}
	
}
